package cn.aitrox.ry.service.anno.bo.ultrasound.video;


import cn.aitrox.ry.util.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class VideoInfoBo {

    // 总帧数
    private Integer videoFrames;

    // 帧率
    private Double videoFrameRate;

    // 总时长：纳秒
    private Long lengthInTime;

    // 帧图片宽
    private Integer imageWidth;

    // 帧图片高
    private Integer imageHeight;

    // DCM tag
    private Double frameTime;

    public Map<String, String> convertMap() {
        Map<String, String> map = new HashMap<>();
        for (Field field : VideoInfoBo.class.getDeclaredFields()) {
            boolean flag = field.isAccessible();
            field.setAccessible(true);
            String fieldName = field.getName();
            Object obj = null;
            try {
                obj = field.get(this);
            } catch (IllegalAccessException e) {
            }
            if (null != obj) {
                map.put(fieldName, obj.toString());
            }
            field.setAccessible(flag);
        }
        return map;
    }

    public static VideoInfoBo mapToObj(Map<String, String> map) {
        if (null == map) {
            return null;
        }
        return JSONUtil.parseObject(JSONUtil.toJson(map, map.getClass()), VideoInfoBo.class);
    }
}
